/*
 * HashUtils.java
 *
 * Copyright (c) 2006 Computer-Aided Integrated Systems Laboratory, 
 * St. Petersburg Institute for Informatics and Automation RAS http://cais.lisa.iias.spb.su
 */

package topindex;

import Ontology.*;
import java.util.*;

public class HashUtils {

    /** Creates HashMap from class name to class object */
    public static Map<String, Classes> createMapClassNameToObject(Hashtable htClasses) {
        
        HashMap<String, Classes> class_name2object = new HashMap<String, Classes>();
        
        if(null == htClasses) {
            System.out.println("Warning! WebDeso WDO htClasses is null in HashUtils.createMapClassNameToObject");
        } else {
            for(Object id:htClasses.keySet()) {
                Classes c = (Classes)htClasses.get((Integer)id);
                String name = c.getClassName();

                if(class_name2object.containsKey(name)) {
                    //c  = class_name2object.get(name);
                    System.out.println("Attention! Duplicate class name in WebDeso '"+name+"'");
                }
                else {
                    class_name2object.put(name, c);
                }
            }
        }
        return class_name2object;
    }
    
    
    /** Creates HashMap from attribute name to attribute object */
    public static Map<String, Attributes> createMapAttrNameToObject(Hashtable htAttributes) {
        
        HashMap<String, Attributes> attr_name2object = new HashMap<String, Attributes>();
        
        if(null == htAttributes) {
            System.out.println("Warning! WebDeso WDO htAttributes is null in HashUtils.createMapAttrNameToObject");
        } else {
            for(Object id:htAttributes.keySet()) {
                Attributes c = (Attributes)htAttributes.get((Integer)id);
                String name = c.getAttrName();

                if(!attr_name2object.containsKey(name)) {
                    attr_name2object.put(name, c);
                }
                //else {
                //    System.out.println("Attention! Duplicate attributes name in WebDeso '"+name+"'");
                //}
            }
        }
        return attr_name2object;
    }
}
